package com.ebt.m.proposal_v2.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import com.ebt.m.AppContext;
import com.ebt.m.R;
import com.ebt.m.activity.LoginActivity;
import com.ebt.m.utils.UIHelper;
import com.ebt.m.widget.BaseActivity;

public class ActProposalList extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!AppContext.getCurrentUser().isLogined()) {
            UIHelper.makeToast(getApplicationContext(), "您还没有登录");
            gotoLogin();
            return;
        }
        setContentView(R.layout.act_proposal_list);
        setDefaultFragment();
    }

    private void setDefaultFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.content_frame, FragmentProposalList.newInstance(true), "proposal_list_fragment");
        ft.commitAllowingStateLoss();
    }

    private void gotoLogin() {
        Intent loginIntent = new Intent(ActProposalList.this, LoginActivity.class);
        startActivity(loginIntent);
    }
}